<?xml version="1.0" encoding="UTF-8" ?>
<%@ page language="java" contentType="text/html; charset=UTF-8"	pageEncoding="UTF-8"%>
<%@ taglib uri="http://www.springframework.org/tags" prefix="spring"%>
<%@ taglib prefix="c" uri="http://java.sun.com/jsp/jstl/core"%>
<%@ taglib uri="http://java.sun.com/jsp/jstl/functions" prefix="fn" %>
<%@ taglib uri="http://java.sun.com/jsp/jstl/fmt" prefix="fmt"%>
<%@ taglib uri="/WEB-INF/tld/PagingA.tld" prefix="pagingTagA"%>

<section id="boxListChapter" class="boxSubject corner3 rightShadow">
	<div class="boxTitle topCorner3">
		<h2 class='textOverflow'>Danh sách chương của truyện tình cảm <span>${truyen.name}</span></h2>
	</div>
	<c:set var="aliasTruyen">${fn:replace(truyen.alias,' ','-')}</c:set>
	<ul class="listChapter">
		<c:choose>
			<c:when test="${lstChapterTruyen.size() > 0}">
				<c:forEach items="${lstChapterTruyen}" var="item">
					<c:set var="chapterNumber"><fmt:formatNumber type="number" maxIntegerDigits="4" value="${item.chapterNumber}" pattern="###.###" /></c:set>
					<li><a href="<spring:url value="/truyen-tinh-cam/${aliasTruyen}-chuong-${fn:replace(chapterNumber,',','')}-T${truyen.id}-C${item.id}.htm" />" title="${item.name}">Chương ${chapterNumber}</a></li>
				</c:forEach>
			</c:when>
			<c:otherwise><li>Đang cập nhật...</li></c:otherwise>
		</c:choose>
	</ul>
	<c:if test="${pInfoChapter.totalPage > 1}">
		<section class="pagination">
			<form>
				<spring:url value="/truyen-tinh-cam/T${truyen.id}/${aliasTruyen}" var="link" />
				<pagingTagA:paging searchUrl="${link}" curPageParam=".htm?curPage=" 
						searchValueParam="#boxListChapter" pagingInf="${pInfoChapter}"></pagingTagA:paging>
				<input type="text" id="goToChapter" class='validate[custom[numberFloat]]' placeholder="go..." size="7" /> / ${countChapter}
				<button type="button" id='gChapter' class='corner3 buttonOrange'>Go</button>
				<script type="text/javascript">
					$(function(){
						$('#goToChapter, #gChapter').change(function(){
							var chapterNumber = $(this).val();
							var countChapter = ${countChapter};
							if(chapterNumber > 0 && chapterNumber <= countChapter ){
								var idTruyen = "${truyen.id}";
								$.ajax({
									type: "POST",
									async:false,
									url: "<spring:url value='/truyen-tinh-cam/findChapter.htm' />",
									data: {idTruyen:idTruyen,chapterNumber:chapterNumber},
									success: function(rs){
										if(rs != "0"){
											var link = "<spring:url value='/truyen-tinh-cam/${aliasTruyen}-chuong-"+chapterNumber+"-T${truyen.id}-C"+rs+".htm' />";
											location.replace(link);
										}
							   		}
								});
							}
						});
					});
				</script>
			</form>
		</section>
	</c:if>
</section>